<template>
  <view class="item">
    <view class="content">
      <view>
        <image src="../../static/hha/sfztx.png"></image>
      </view>
      <view class="smrz"> 实名认证</view>
      <view class="smrz2">
        姓名与支付宝实名认证信息相关联且不可更改 <br/>
        提交既同意支付宝采集人脸照片用于实名认证
      </view>
    </view>
    <view class="bs_xx">
      <view class="sfxx d-c-c d-c">
        <view class="sfxx3">
          <view class="sfxx4 d-s-s d-c">
            <view style="font-size: 30rpx"> 姓名：</view>
            <u--input placeholder="您的姓名" border="surround" :customStyle="{width: '90%', marginTop: '10rpx'}"
                      v-model="value1"></u--input>
          </view>

          <view class="sfxx4 d-s-s d-c">
            <view style="font-size: 30rpx"> 身份证号：</view>
            <u--input placeholder="您的身份证号" border="surround"
                      :customStyle="{width: '90%', marginTop: '10rpx'}" v-model="value2"></u--input>
          </view>
        </view>

        <view class="anniu">
          <u-button type="primary" text="确定" @click="queding()" :disabled='isdisabled'></u-button>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      value1: "",
      value2: "",
      id: "",
      dataurl: "",
      mobile: "",
      isdisabled: false

    };
  },
  onLoad(e) {
    this.id = e.order_id;
    this.getinfo();
  },
  methods: {
    getinfo() {
      let self = this;
      self._get("user.index/setting", {}, function (res) {
        console.log(res.data.userInfo.username, res.data.userInfo.usernum);
        self.value1 = res.data.userInfo.username;
        self.value2 = res.data.userInfo.usernum;
        self.mobile = res.data.userInfo.mobile
      });
    },
    queding() {
      let self = this;
      console.log(self.value1, self.value2);
      self.isdisabled = true
      if (uni.$u.test.idCard(self.value2) == false) {
        uni.showToast({
          title: "身份证号码有误,请重填！",
          duration: 2000,
          icon: "none",
        });
        self.isdisabled = false
        return;
      }

      if (self.value1 == "") {
        uni.showToast({
          title: "姓名不能为空！",
          duration: 2000,
          icon: "none",
        });
        self.isdisabled = false
        return;
      }
      uni.showLoading({
        title: '加载中',
        mask: true
      });
      self._post("user.user/realNameAuthentication", {username: self.value1, usernum: self.value2, mobile: self.mobile}, function (res) {
            self.isdisabled = false
            uni.hideLoading();
            // let huoti = uni.getStorageSync('huoti') // 在app.vue中设置的（根据设置-订单配置中的掌签征信/点汇征信是否打开）
            if (res.code == 1) {
              // 改为e签宝人脸
              self._post('esign.Eqb/authFace', {username: self.value1, usernum: self.value2, order_id: self.id, mobile: self.mobile}, (res) => {
                self.isdisabled = true
                my.ap.openURL({
                  url: res.data.originalUrl,
                  success: (ress) => {
                    const timer = setInterval(() => {
                      self._post('order.contract/getface', {
                        order_id: self.id,
                        flowId: res.data.flowId
                      }, (getfaceRes) => {
                        if (getfaceRes['data']['status'] == 'SUCCESS') {
                          uni.showToast({
                            title: "已获取到了状态",
                            duration: 2000,
                            icon: "none",
                          });
                          clearInterval(timer); // 停止定时器
                        }
                      })
                    }, 2000);
                  }
                })
              })
            } else {
              let param = {username: self.value1, usernum: self.value2, mobile: self.mobile, order_id: self.id}
              self._post('esign.Eqb/face', param, (res) => {
                    my.ap.openURL({
                      // originalUrl 长链接，authUrl 短链接
                      url: res.data.data.authUrl,
                      success: (ress) => {
                        console.log(ress, 'resss')
                      }
                    });
                  },
                  function (err) {
                    console.log(err)
                  })
            }
            /* // 改用支付宝人脸识别
            if (huoti == true) {
              self._post('order.order/faceAuthentication', {
                username: self.value1,
                usernum: self.value2,
                order_id: self.id,
                mobile: self.mobile
              }, (res) => {
                self.isdisabled = true
                my.ap.openURL({
                  url: res.data.url,
                  success: (ress) => {
                    setTimeout(e => {
                      // self._post('order.contract/getface', {
                      // 	order_id: self.id,
                      // 	flowId: res.data.flowId,
                      // }, (ress) => {
                      // 	uni.navigateBack();
                      // })
                    }, 2000)

                  }
                })
              })
            } */
          }
      );
    },
    // onWebviewMessage(message) {
    // 	console.log('onWebviewMessage>>>>>', message)
    // 	const {detail: {type,token,url}} = message
    // 	if (type === 'IDENTITY_ALI_FACE_AWAKE') {
    // 		//拉起支付宝刷脸认证
    // 		my.startAPVerify({
    // 			url,
    // 			certifyId: token,
    // 			success: function(res) {
    // 				console.log('success', res)
    // 			},
    // 			fail: function(res) {
    // 				console.log('fail', res)
    // 			},
    // 			complete: function(res) {
    // 				console.log('complete', res)
    // 			}
    // 		})
    // 		return
    // 	}
    // 	//认证授权暂不支持以下两种type的识别
    // 	if (type === 'WILL_DONE') {
    // 		console.log('WILL_DONE>>do something')
    // 		return
    // 	}
    // 	if (type === 'RN_DONE') {
    // 		console.log('RN_DONE>>do something')
    // 		return
    // 	}

    // }
  },
};
</script>

<style lang="scss">
.item {
  height: calc(100vh + 400rpx);
}

.content {
  width: 100%;
  height: 400rpx;
  background-color: #53a9f4;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;

  image {
    width: 150rpx;
    height: 150rpx;
  }

  .smrz {
    color: #ffffff;
    margin-top: 20rpx;
    font-size: 30rpx;
  }

  .smrz2 {
    color: #ffffff;
    margin-top: 20rpx;
    line-height: 34rpx;
  }
}

.bs_xx {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  background: #f5f5f5;

  .sfxx {
    width: 100%;
    padding: 0 15rpx 15rpx 15rpx;
    background-color: #ffffff;

    .sfxx2 {
      padding: 20rpx 20rpx;

      view {
        color: #43a3e8;
        margin-top: 10rpx;
      }
    }

    .sfxx3 {
      .sfxx4 {
        display: flex;
        width: 600rpx;
        padding: 0;
        margin-top: 20rpx;
      }
    }
  }

  .anniu {
    margin-top: 20rpx;
    width: 85%;
    border-radius: 50rpx;
  }
}
</style>